package com.qf.homeworkssm.controller;


import com.qf.homeworkssm.entity.ApiMapping;
import com.qf.homeworkssm.service.ApiService;
import com.qf.homeworkssm.vo.ResultVo;
import com.qf.homeworkssm.vo.TableVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/api_mapping")
@Slf4j
public class ApiController {

    @Autowired
    private ApiService apiService;


    //分页

    @GetMapping("/table")
    public TableVo<ApiMapping> table(Integer page, Integer limit, ApiMapping apiMapping){

        log.debug("传入的参数  page={},limit={},apiMapping={}",page,limit,apiMapping);

        //调用service分页
        TableVo<ApiMapping> tableVo = apiService.getApiByTable(page,limit,apiMapping);
        return tableVo;

    }

    @PostMapping("/add")
    public ResultVo add(ApiMapping apiMapping){

        log.debug("收到的参数是：apiMapping={}" ,apiMapping);
        //调用apiService层接收参数
        ResultVo resultVo = apiService.inserApi(apiMapping);
        return resultVo;

    }

    @RequestMapping("del")
    public ResultVo del(Integer[] ids){

        log.debug("接收的数据参数是 ids= {}" ,ids);

        ResultVo resultVo = apiService.del(ids);

        return resultVo;
    }


    @RequestMapping("/update")
    public ResultVo update(ApiMapping apiMapping){

        log.debug("收到的参数api={}",apiMapping);

        ResultVo resultVo = apiService.update(apiMapping);
        return resultVo;

    }





}
